package com.jerry.chat.service;

import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.errors.*;
import io.minio.http.Method;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@Service
public class MinioServiceImpl implements MinioService {

    private MinioClient minioClient;

    public MinioServiceImpl()
    {
        minioClient = MinioClient.builder()
                .endpoint("http://192.168.1.7:9000")
                .credentials("minioadmin", "minioadmin")
                .build();
    }

    @Override
    public String getFileUploadPath(String bucket, String filename) {
        try {
            return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
                    .method(Method.PUT)
                    .bucket(bucket)
                    .object(filename)
                    .build());
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "";
    }
}
